<template>
  <div class="cropper-wrapper" v-if="isShowCropper">
    <VueCropper
      autoCrop
      :img="cropperImg"
      ref="cropper"
      enlarge="1"
      :canMoveBox="false"
      :canMove="true"
      :fixedBox="true"
      centerBox
      fixed
      :fixedNumber="fixedNumber"
      mode="contain"
    />
    <!-- :outputSize="0.8" 默认不压缩 -->
    <button class="cancel" @click="onCancel">取消</button>
    <button class="crop" @click="onCrop">确定</button>
    <!-- <div class="cropper-btn">
      <div @click="onCancel">取消</div>
      <div @click="onCrop">确定</div>
    </div> -->
  </div>
</template>

<script>
export default {
  props: ['isShowCropper', 'cropperImg', 'fixedNumber'],
  data() {
    return {}
  },
  methods: {
    onCrop() {
      this.$refs.cropper.getCropData((data) => {
        this.$emit('hasCropped', {
          type: 'crop',
          url: data,
        })
      })
    },
    onCancel() {
      this.$emit('hasCropped', {
        type: 'cancel',
      })
    },
  },
}
</script>

<style lang="scss" scope>
.cropper-wrapper {
  position: fixed;
  width: 100vw;
  height: 100vh;
  left: 0;
  top: 0;
  z-index: 10006;
  .cancel {
    width: 2.7rem;
    height: 1.02rem;
    background: #ffffff;
    border: 1px solid #707070;
    border-radius: 0.06rem;
    font-size: 0.38rem;
    color: #292b2f;
    position: fixed;
    bottom: 0.65rem;
    left: 0.75rem;
  }
  .crop {
    width: 2.7rem;
    height: 1.02rem;
    background: linear-gradient(#22a0fe, #145afe);
    border-radius: 0.06rem;
    font-size: 0.38rem;
    color: #ffffff;
    position: fixed;
    bottom: 0.65rem;
    right: 0.75rem;
  }
  // .cropper-btn {
  //   position: fixed;
  //   bottom: 0;
  //   left: 0;
  //   width: 100%;
  //   height: 0.8rem;
  //   line-height: 0.8rem;
  //   display: flex;
  //   background: #fff;
  //   div {
  //     color: #145afe;
  //     width: 50%;
  //     text-align: center;
  //     font-size: 0.32rem;
  //   }
  // }
}
// 自定义cropper样式
.cropper-wrapper {
  .crop-info {
    display: none;
  }
  .vue-cropper {
    background-image: none !important;
    background-color: rgba(0, 0, 0, 1) !important;
  }
}
</style>
